#include <iostream>
#include <string>
using namespace std;
// cpu
class AbstructCpu
{
public:
    virtual void calculator() = 0; // 计算
};
// 显卡
class AbstructVideoCard
{
public:
    virtual void display() = 0; // 显示
};
// 内存条
class AbstructMemory
{
public:
    virtual void storage() = 0; // 存储
};
// 电脑
class Computer
{
private:
    AbstructCpu *c_cpu;
    AbstructVideoCard *c_videoCard;
    AbstructMemory *c_memory;

public:
    Computer(AbstructCpu *cpu, AbstructMemory *memory, AbstructVideoCard *videoCard)
    {
        c_cpu = cpu;
        c_videoCard = videoCard;
        c_memory = memory;
    }
    ~Computer()
    {
        cout << "执行Computer的析构函数" << endl;
        if (c_cpu != NULL)
        {
            delete c_cpu;
            c_cpu = NULL;
        }
        if (c_memory != NULL)
        {
            delete c_memory;
            c_memory = NULL;
        }
        if (c_videoCard != NULL)
        {
            delete c_videoCard;
            c_videoCard = NULL;
        }
    }
    void work()
    {
        c_cpu->calculator();
        c_videoCard->display();
        c_memory->storage();
    }
};
// 厂商生产零件
class InterCpu : public AbstructCpu
{
public:
    virtual void calculator()
    {
        cout << "Inter Cpu 开始计算!" << endl;
    }
};
class InterMomory : public AbstructMemory
{
public:
    virtual void storage()
    {
        cout << "Inter 内存条 开始存储!" << endl;
    }
};
class LenovoVidoCard : public AbstructVideoCard
{
public:
    virtual void display()
    {
        cout << "lenovo 显卡 开始显示!" << endl;
    }
};
//  组装电脑工作
void test()
{
    // 生产零件
    InterCpu *cpu = new InterCpu;
    InterMomory *memory = new InterMomory;
    LenovoVidoCard *videoCard = new LenovoVidoCard;

    // 组装第一台电脑
    Computer *computer1 = new Computer(cpu, memory, videoCard);
    // 电脑工作
    computer1->work();
    delete computer1;
    cout << "--------------------------------" << endl;
    // 组装第二台电脑
    Computer *computer2 = new Computer(new InterCpu, new InterMomory, new LenovoVidoCard);
    // 电脑工作
    computer2->work();
    delete computer2;
};

int main()
{
    test();
    return 0;
}